/*
 * @Author: 一路向阳 tt_sunzhenfeng@163.com
 * @Date: 2024-02-05 22:07:08
 * @LastEditors: 一路向阳 tt_sunzhenfeng@163.com
 * @LastEditTime: 2024-02-08 18:58:16
 * @FilePath: \utils_react_manager\server\router\login.js
 * @Description: 登录模块
 */
const Router = require('koa-router');
const JWT = require('koa-jwt');
const secret = require('../modules/jwt');
const {
  userDetail,
  getCaptchaCode,
  register,
  login
} = require('../controller/loginController');

const router = new Router();

const jwt = JWT({ secret })

// 用户详情
router.get('/api/userDetail', jwt, async ctx => {
  await userDetail(ctx);
});

// 获取验证码
router.get('/getCaptchaCode', async ctx => {
  await getCaptchaCode(ctx);
});

router.post('/register', async ctx => {
  await register(ctx);
});

router.post('/login', async ctx => {
  await login(ctx);
});

module.exports = router;